package com.allwees.bs.core.model.order.entity;

import com.allwees.bs.core.modelbase.entity.BaseEntity;
import com.allwees.core.common.util.MoneyUtil;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.NoArgsConstructor;

import javax.persistence.Column;
import javax.persistence.MappedSuperclass;
import java.math.BigDecimal;

@Data
@EqualsAndHashCode(callSuper = true)
@NoArgsConstructor
@MappedSuperclass
public class OrderRefundItemModel extends BaseEntity {
    @Column(length = 64, updatable = false)
    private String orderUuid;

    @Column(length = 64, updatable = false)
    private String orderRefundUuid;

    @Column(length = 64, updatable = false)
    private String orderItemUuid;

    @Column(length = 64, updatable = false)
    private String productUuid;

    @Column(length = 64, updatable = false)
    private String skuUuid;

    // 购买数量
    private Integer quantity;

    // 价格
    private BigDecimal price;

    // 金额
    private BigDecimal amount;


    /**
     * 退款总金额
     */
    protected BigDecimal refundTotalAmt;

    /**
     * 商品退款
     */
    protected  BigDecimal refundProductAmt;
    /**
     *  运费退款
     */
    protected BigDecimal refundShippingAmt;

    /**
     * 支付方式
     */
    protected String  payType;

    /**
     * Cash退款
     */
    protected BigDecimal  refundAmtCash;

    /**
     * Paypal退款
     */
    protected BigDecimal  refundAmtPaypal;


    /**
     * 买家id
     */
    protected String userUuid;


    public OrderRefundItemModel(OrderItemModel orderItem) {
        this.orderUuid = orderItem.getOrderUuid();
        this.orderItemUuid = orderItem.getUuid();

        this.productUuid = orderItem.getProductUuid();
        this.skuUuid = orderItem.getSkuUuid();

        this.amount = orderItem.getAmt();
        this.price = orderItem.getPrice();
        this.quantity = orderItem.getQuantity();

        //退款总金额 = paypal或者credit card 支付金额 +  cash支付金额
        this.refundTotalAmt = MoneyUtil.add(orderItem.getAmt(),orderItem.getAmtCashSku());
        this.refundProductAmt = orderItem.getAmtSku();
        this.refundShippingAmt = orderItem.getAmtShipping() ;
        this.payType =  MoneyUtil.isNullOrZero(orderItem.getAmt())? "coupon":"payby" ;
        this.refundAmtCash = orderItem.getAmtCashSku();
        this.refundAmtPaypal = orderItem.getAmt() ;
        this.userUuid = orderItem.getUserUuid();
    }
}
